/******************************************************************************
 * @file bsp_led_driver.h
 * @brief led bsp driver header file
 *
 * 详细描述：
 * - 功能1：具体描述
 * - 功能2：具体描述
 * - ...
 *
 * @author jiaqi.lou
 * @date 2024-11-25
 * @version v1.0
 *
 * @note 备注信息 (可选)
 * @warning 警告信息 (可选)
 ******************************************************************************/
#ifndef __BSP_LED_DRIVER_H
#define __BSP_LED_DRIVER_H

/****************************** include **************************************/
#include <stdio.h>
#include <stdint.h>
/****************************** include **************************************/

/****************************** define  **************************************/
#define OS_SUPPORT                  /* OS_SUPPORTING depending on OS availabel */
#define INITED          1           /* LED is inited */
#define NOT_INITED      0           /* LED is not inited */
#define DEBUG_OUT(X)    printf(X)   /* DEBUG output info indicate status */
/****************************** define  **************************************/

/****************************** declare **************************************/

typedef struct  bsp_led_driver_t bsp_led_driver_t;

/**
 * @brief led driver status
 *
 */
typedef enum
{
    LED_OK = 0U,               /*led no error*/
    LED_ERROR = 1U,            /*led driver occurs error*/
    LED_ERROR_TIMEOUT = 2U,    /*led driver time out*/
    LED_ERROR_RESOURCES = 3U,  /*led resource randuncy or loss*/
    LED_ERROR_PARAMETER = 4U,  /*led param wrong*/
    LED_ERROR_NOMEMORY = 5U,   /*led lack memory*/
    LED_ERROR_ISR = 6U,        /*led error from isr */
    LED_ERROR_BUSY = 7U,       /*led driver is running */
    LED_ERROR_RESERVED = 0XFF, /*reserved*/

} led_status_t;

/**
 * @brief list proportion of led blink
 *
 */
typedef enum
{
    PROPORTION_1_3 = 1U,   /*on/off ratio 1:3*/
    PROPORTION_1_2 = 2U,   /*on/off ratio 1:2*/
    PROPORTION_1_1 = 3U,   /*on/off ratio 1:1*/
    PROPORTION_X_X = 0xFF, /*Reserved*/
} led_proportion_t;

/**
 * @brief led operation function pointer
 *
 */
typedef struct
{
    led_status_t (*pf_led_on)(void);  /*led on function pointer*/
    led_status_t (*pf_led_off)(void); /*led off function pointer*/
} led_operation_t;

/**
 * @brief led timebase function pointer
 *
 */
typedef struct
{
    led_status_t (*pf_led_get_tick)(uint32_t * const); /*get tick function pointer*/
} led_timebase_t;

#ifdef OS_SUPPORT
typedef struct
{
    led_status_t (*pf_led_os_delay)(const uint32_t); /*os delay function pointer*/
} led_os_delay_t;
#endif /* end of os_support*/

typedef led_status_t (*led_control)
    (    bsp_led_driver_t * const self, /*led driver instance*/
        uint32_t cycletime,    /*cycle time*/
        uint32_t  times,         /*times*/
        led_proportion_t  prot);/*prot input*/ 

/**
 * @brief led driver structure
 *
 */
typedef struct bsp_led_driver_t
{
    /****************************** status **************************************/
    uint8_t inited; /*led driver inited status*/
    /****************************** feature **************************************/
    uint32_t blink_period_ms;           /*led blink period[ms]*/
    uint32_t blink_times;               /*led blink times*/
    led_proportion_t proportion_on_off; /*led blink on time[ms]*/

    /****************************** func pointer *********************************/
    led_operation_t *p_led_operation; /*led operation function pointer*/
    led_timebase_t *p_led_timebase;   /*led timebase function pointer*/
#ifdef OS_SUPPORT
    led_os_delay_t *p_led_os_delay; /*led task handle*/
#endif                              /* end of os_support*/
    /****************************** target api *********************************/
    // led_control pf_led_control; /*led control function pointer*/
    led_control  pf_led_control; /*led control function pointer*/
} bsp_led_driver_t;

/****************************** declare **************************************/
/**
 * @brief led driver instance init
 * @param[in] self led driver instance
 * @param[in] p_led_operation led on/off function pointer   
 * @param[in] p_led_timebase led timebase function pointer
 * @param[in] p_led_os_delay os delay function pointer
 */
led_status_t bsp_led_instance(
    bsp_led_driver_t * const self, /*led driver instance*/
    led_operation_t *const p_led_operation, /*led operation function pointer*/
    led_timebase_t *const p_led_timebase,   /*led timebase function pointer*/
#ifdef OS_SUPPORT
    led_os_delay_t *p_led_os_delay /*os delay function pointer*/
#endif                              /* end of os_support*/
    );



#endif // __BSP_LED_DRIVER_H